import os
from typing import List
from tortoise import Tortoise
from app.config import settings

async def execute_sql_file(file_path: str) -> None:
    """执行SQL文件"""
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            sql_content = f.read()
            
        # 按分号分割SQL语句
        sql_statements = [s.strip() for s in sql_content.split(';') if s.strip()]
        
        # 获取数据库连接
        conn = Tortoise.get_connection("default")
        
        # 执行每条SQL语句
        for sql in sql_statements:
            await conn.execute_query(sql)
            
    except Exception as e:
        print(f"执行SQL文件失败: {str(e)}")
        raise 